# Input
# 1-5
# 2
# Output
# 1,3-5

# Input
# 20-21,15,18,30,5-10
# 15
# Output
# 5-10,18,20-21,30

# Input
# 5,1-3
# 10
# Output
# 1-3,5

def main():
    #1. get input
    vlan_pool_input = input().strip() # input vlan pool
    dest_vlan = int(input().strip()) # input dest vlan

    #2. main process: remove target from vlan pool
    vlan_pool = [] # vlan pool list
    vlan_group = vlan_pool_input.split(",") # split vlan_pool_input by ","

    for vlan_item in vlan_group:
        if "-" in vlan_item:
            # if vlan item is the scope
            vlan_items = vlan_item.split("-") # split the scope
            start_vlan = int(vlan_items[0])
            end_vlan = int(vlan_items[1])
            # add vlans to vlan pool
            for j in range(start_vlan, end_vlan + 1):
                vlan_pool.append(j)
            continue
        else:
            vlan_pool.append(int(vlan_item))

    # sort vlan pool in ascend order
    vlan_pool.sort()

    if dest_vlan in vlan_pool:
        # if dest vlan in pool
        vlan_pool.remove(dest_vlan) # remove

    #3. make result
    result = []
    last_vlan = None

    for index in range(len(vlan_pool)):
        current = vlan_pool[index]

        if last_vlan is None: # if current is 1st
            result.append(str(current))
            last_vlan = current
            continue
        
        if current - last_vlan == 1: # if current is consective with last
            # if the last data in result end with "-last_vlan" 
            if result[-1].endswith("-" + str(last_vlan)):
                result[-1] = result[-1][:result[-1].rindex(str(last_vlan))] + str(current) # update to "-current"
            else:
                result.append("-" + str(current)) # add "-current"
        else:
            result.append("," + str(current)) # add ",current"
        last_vlan = current

    # print result
    print("".join(result)) 

if __name__ == "__main__":
    main()